package com.wmjsoft.plugins.security.user

object CurrentUser {

    /**
     * 当前线程用户
     */
    private val userHolder: ThreadLocal<UserDetails> = ThreadLocal<UserDetails>()

    /**
     * 设置当前线程的用户
     *
     * @param user user
     */
    fun setCurrentUser(user: UserDetails?) {
        userHolder.set(user)
    }

    /**
     * 取得当前线程中的用户
     */
    fun getCurrentUser(): UserDetails {
        return userHolder.get()
    }

    /**
     * 清除当前线程用户
     */
    fun clearCurrentUser() {
        userHolder.remove()
    }

    fun currentUser(): Any? {
        return getCurrentUser().id
    }
}